

/*
* Copyright @ 2017 com.iflysse.trains
* crm 上午1:22:09
* All right reserved.
*
*/
	
package com.qf.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.qf.dto.CrmCourseDto;
import com.qf.pojo.CrmCourseType;
import com.qf.pojo.PageBean;
import com.qf.pojo.PageCourse;
import com.qf.service.CrmCourseTypeService;

/**
* @desc: crm
* @descripe:XXXX
* @author: 周锐
* @createTime: 2017年7月26日 上午1:22:09
* @history:
* @version: v1.0

*/
@Controller
public class CrmCourseTypeServlet {
    @Autowired
    @Qualifier("crmCourseTypeService")
	private CrmCourseTypeService cts;
    
	
	/**
	* @param cts the cts to set
	*/
	
	public void setCts(CrmCourseTypeService cts) {
	
		this.cts = cts;
	}
	@RequestMapping("/addCourse.do")
    public ModelAndView addCourse(HttpServletRequest request,HttpServletResponse response){
    	ModelAndView mv=new ModelAndView();
    	String courseName = request.getParameter("courseName");
    	String total=request.getParameter("total");
    	String courseCost=request.getParameter("courseCost");
    	String remark = request.getParameter("remark");
    	CrmCourseType course=new CrmCourseType();
    	course.setCourseName(courseName);
    	course.setTotal(Integer.parseInt(total));
    	course.setCourseCost(Double.parseDouble(courseCost));
    	course.setRemark(remark);
    	cts.addCourseType(course);
    	mv.setViewName("findbypageCourses.do");
		return mv;
    	
    }
	@RequestMapping("/findbypageCourses.do")
	 public ModelAndView findbypageCourses(HttpServletRequest request,HttpServletResponse response){
		 ModelAndView mv=new ModelAndView();
	    	String page_=request.getParameter("page");
	    	int page=1;
	    	int size=3;
	    	if(page_!=null){
	    		page=Integer.parseInt(page_);
	    	}
	    	PageCourse pageCourse = cts.findByPage(page, size);
	    	mv.addObject("pageCourse", pageCourse);
	    	mv.setViewName("/pages/coursetype/listCourse.jsp");
	    	return mv;
}
	@RequestMapping("/preupdateCourse.do")
	 public ModelAndView preupdateCourse(HttpServletRequest request,HttpServletResponse response){
		ModelAndView mv=new ModelAndView();
		String courseTypeId=request.getParameter("courseTypeId");
		String courseName = request.getParameter("courseName");
    	String total=request.getParameter("total");
    	String courseCost=request.getParameter("courseCost");
    	String remark = request.getParameter("remark");
    	CrmCourseType courses=new CrmCourseType();
    	courses.setCourseTypeId(Long.valueOf(courseTypeId));
    	courses.setCourseName(courseName);
    	courses.setTotal(Integer.parseInt(total));
    	courses.setCourseCost(Double.parseDouble(courseCost));
    	courses.setRemark(remark);
    	mv.addObject("courses", courses);
    	mv.setViewName("/pages/coursetype/editCourse.jsp");
		return mv;
}
	@RequestMapping("/updateCourse.do")
	 public ModelAndView updateCourse(HttpServletRequest request,HttpServletResponse response){
		ModelAndView mv=new ModelAndView();
		String courseTypeId=request.getParameter("courseTypeId");
		String courseName = request.getParameter("courseName");
    	String total=request.getParameter("total");
    	String courseCost=request.getParameter("courseCost");
    	String remark = request.getParameter("remark");
    	CrmCourseType courseType = cts.findbyId(Long.valueOf(courseTypeId));
    	courseType.setCourseName(courseName);
    	courseType.setTotal(Integer.parseInt(total));
    	courseType.setCourseCost(Double.parseDouble(courseCost));
    	courseType.setRemark(remark);
    	cts.updateCourse(courseType);
    	mv.setViewName("findbypageCourses.do");
		return mv;
}
	@RequestMapping("/findCourse.do")
	 public ModelAndView findCourse(HttpServletRequest request,HttpServletResponse response){
		ModelAndView mv=new ModelAndView();
		String courseName=request.getParameter("courseName");
		String totalStart = request.getParameter("totalStart");
		String totalEnd=request.getParameter("totalEnd");
		String page_=request.getParameter("page");
    	int page=1;
    	int size=3;
    	if(page_!=null){
    		page=Integer.parseInt(page_);
    	}
		PageCourse pageCourse = cts.findCourse(courseName, Integer.parseInt(totalStart), Integer.parseInt(totalEnd),page,size);
		mv.addObject("pageCourse", pageCourse);
		mv.addObject("courseName", courseName);
		mv.addObject("totalStart", totalStart);
		mv.addObject("totalEnd", totalEnd);
	    mv.setViewName("/pages/coursetype/findnamelistCourse.jsp");
	    return mv;
	
}
	@RequestMapping("/findallCourse.do")
	 public ModelAndView findallCourse(HttpServletRequest request,HttpServletResponse response){
		ModelAndView mv=new ModelAndView();
		List<CrmCourseDto> allCourse = cts.findbyAllCourse();
		mv.addObject("allCourse", allCourse);
		mv.setViewName("/pages/classesm/addOrEditClass.jsp");
		return mv;	
}
}